<template>
    <div class="mainDiv">
        <div class="rowHead">
            <el-button type="success" icon="plus" @click="add" v-show="noadd" v-qx="permission.add">管理员</el-button>
            <el-alert title="机构管理员最多16个且不能删除，可通过修改权限使用帐号。" type="warning" :closable="false" style="width: 500px">
            </el-alert>
        </div>
        <el-table :data="list" :stripe="true" height="100%">
            <el-table-column prop="id" label="#"></el-table-column>
            <el-table-column prop="username" label="帐号"></el-table-column>
            <el-table-column prop="name" label="姓名"></el-table-column>
            <el-table-column prop="phone" label="电话"></el-table-column>
            <el-table-column prop="remarks" label="描述" :show-overflow-tooltip="true"></el-table-column>
            <el-table-column prop="gradeid" label="权限等级"></el-table-column>
            <el-table-column prop="miaoshu" label="权限描述" :show-overflow-tooltip="true"></el-table-column>
            <el-table-column label="设置">
                <template scope="scope">
                    <el-button-group>
                        <!-- <el-button type="warning" icon="edit" content="编辑" size="small" @click="edit(scope.row)" v-qx="permission.edit"></el-button> -->
                        <el-tooltip content="编辑" placement="top" :open-delay="800" v-qx="permission.edit">
                            <el-button type="warning" icon="el-icon-edit" content="编辑" size="mini" @click="edit(scope.row)" v-qx="permission.edit"></el-button>
                        </el-tooltip>
                        <el-tooltip content="设置账户权限" placement="top" :open-delay="800" v-qx="permission.set">
                            <el-button type="primary" icon="el-icon-h-set2" size="mini" @click="setqx(scope.row.id,scope.row.rid)"></el-button>
                        </el-tooltip>
                        <!-- <el-button type="danger" icon="delete2" size="small" @click="del(scope.row.id)"></el-button> -->
                    </el-button-group>
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>
<script>
import C from '#/src/common/common.js'
export default {
    name: 'groupAdminlist',
    data() {
        return {
            list: [],
            noadd: true,
            permission: {
                add: 'orzhanghao_add',
                edit: 'orzhanghao_edit',
                set: 'orzhanghao_set',
            }
        }
    },
    mounted() {
        this.getList()
    },
    methods: {
        add: async function() {
            let res = await C.openBrowserWindow('/groupAdd', {}, {
                transparent: true,
                frame: false,
                width: 400,
                height: 440,
                useSpa: true,
                spaModel: 'organization'
            })
            if (res) {
                C.success(res.data)
                this.getList()
            }
        },
        edit: async function(row) {
            let res = await C.openBrowserWindow('/groupAdd', { row: row }, {
                transparent: true,
                frame: false,
                width: 400,
                height: 440,
                useSpa: true,
                spaModel: 'organization'
            })
            if (res) {
                C.success(res.data)
                this.getList()
            }
        },
        setqx: async function(id, rid) {
            let res = await C.openBrowserWindow('/groupSelectgrade', { id: id, rid: rid }, {
                transparent: true,
                frame: false,
                width: 800,
                height: 800,
                useSpa: true,
                spaModel: 'organization'
            })
            if (res) {
                C.success(res.data)
                this.getList()
            }
        },
        del: function(id) {
            let that = this
            C.confirm('确定删除当前管理员帐号？', async(res) => {
                let data = await C.ajax('/organization/group/deladmin', { id: id }, 'post')
                if (data) {
                    C.success(data.data)
                    that.getList()
                }
            })
        },
        refresh: function() {
            window.location.reload()
        },
        getList: async function() {
            let res = await C.ajax('/organization/group/adminlist', {}, 'post')
            if (res) {
                this.list = res
                if (res.length > 15) {
                    this.noadd = false
                } else {
                    this.noadd = true
                }
            }
        }
    }
}
</script>